﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace assignment7
{
    public class Order
    {
        public int id { get; set; }
        public string customer { get; set; }
        public double Money { get; set; }
        public string Date { get; set; }

        public List<orderitem> orderitems = new List<orderitem>();

        public Order()
        {//无参构造函数
            this.id = 0;
            this.customer = string.Empty;
            this.Money = 0;
            this.Date = string.Empty;
        }

        public Order(int id, string customer, string Date, List<orderitem> thisorderitems)
        {//有参构造函数
            this.id = id;
            this.customer = customer;
            this.Date = Date;
            this.orderitems = thisorderitems;
        }

        public double getPriceInAll()
        {
            double result = 0;
            foreach (orderitem a in this.orderitems)
            {
                result = result + a.getPrice();//getPrice返回的是一个订单中每一个item它的钱 这个钱实际上是该item的数量乘以该item的单价
            }
            return result;
        }
        // public void addOrderItem(string name,int number,double price){
        //     orderitem a = new orderitem(name,number,price);
        //     this.orderitems.Add(a);
        // }
        public void showorderItem()
        {
            Console.WriteLine("序号 名称 数量 单价");
            foreach (orderitem a in this.orderitems)
            {
                Console.WriteLine("--------------------");
                Console.WriteLine("{0} {1} {2} {3}", this.orderitems.IndexOf(a), a.Name, a.Number, a.Price);
            }
        }
    }
}
